import type {
  ChannelDataSourceForm,
  ChannelDataSourceQuery,
  ChannelDataSourceVO,
} from './model';

import type { ID, IDS, PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
 * 分页查询渠道来源配置列表
 * @param params
 * @returns 渠道来源配置列表
 */
export function channelDataSourcePage(params?: ChannelDataSourceQuery) {
  return requestClient.get<PageResult<ChannelDataSourceVO>>(
    '/channel/data/source/page',
    { params },
  );
}

/**
 * 查询渠道来源配置列表
 * @param params
 * @returns 渠道来源配置列表
 */
export function channelDataSourceList(params?: ChannelDataSourceQuery) {
  return requestClient.get<ChannelDataSourceVO[]>('/channel/data/source/list', {
    params,
  });
}

/**
 * 导出渠道来源配置列表
 * @param params
 * @returns 渠道来源配置列表
 */
export function channelDataSourceExport(params?: ChannelDataSourceQuery) {
  return commonExport('/channel/data/source/export', params ?? {});
}

/**
 * 查询渠道来源配置详情
 * @param id id
 * @returns 渠道来源配置详情
 */
export function channelDataSourceInfo(id: ID) {
  return requestClient.get<ChannelDataSourceVO>(`/channel/data/source/${id}`);
}

/**
 * 新增渠道来源配置
 * @param data
 * @returns void
 */
export function channelDataSourceAdd(data: ChannelDataSourceForm) {
  return requestClient.postWithMsg<void>('/channel/data/source', data);
}

/**
 * 更新渠道来源配置
 * @param data
 * @returns void
 */
export function channelDataSourceUpdate(data: ChannelDataSourceForm) {
  return requestClient.putWithMsg<void>('/channel/data/source', data);
}

/**
 * 更新渠道来源配置状态
 * @param data
 * @returns void
 */
export function channelDataSourceUpdateStatus(data: ChannelDataSourceForm) {
  return requestClient.putWithMsg<void>(
    `/channel/data/source/changeStatus`,
    data,
  );
}

/**
 * 删除渠道来源配置
 * @param id id
 * @returns void
 */
export function channelDataSourceRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/channel/data/source/${id}`);
}
